package com.cssw.fyzb.busi.api.user;


import com.cssw.fyzb.busi.service.user.UserRelService;
import com.cssw.fyzb.core.model.dodb.User;
import com.cssw.fyzb.core.model.vo.user.UserInfoVo;
import com.cssw.fyzb.core.model.vo.user.UserOtherVo;
import com.cssw.fyzb.busi.service.user.DistrictService;
import com.cssw.fyzb.busi.service.user.UserService;
import com.cssw.fyzb.core.model.dodb.District;
import com.cssw.fyzb.core.model.mos.UserMo;
import com.cssw.fyzb.core.util.StringUtil;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 获取他人用户信息
 *
 * @author YangYiQun
 */
@Function(description = "获取用户信息", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户标识", required = true),
        @Parameter(name = "otherUserId", type = Type.String, description = "他人用户标识", required = true)
})
@Component
public class GetUserForOther implements Action {

    @Autowired
    private UserService userService;

    @Autowired
    private DistrictService districtService;

    @Autowired
    private UserRelService userRelService;


    private static final Logger logger = LoggerFactory.getLogger(GetUserForOther.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        Long otherUserId = request.getLong("otherUserId");
        try {
            User user = userService.getById(otherUserId);
            UserOtherVo vo = new UserOtherVo();
            vo.setUserId(user.getUserId());
            vo.setSupUserId(user.getSupUserId());
            vo.setNickName(user.getNickName());
            vo.setMobile(user.getMobile());
            vo.setFaceAuth(user.getFaceAuth());
            //vo.setLive(user.getLive());
            //好友数
            //vo.setFriendsCount(userRelService.getFriendNum(otherUserId));
            //用户作品数
           // vo.setWorksCount(userRelService.cmfCount(otherUserId));
            //喜欢 点赞数
            //vo.setLikeCount(userRelService.findByUserId(otherUserId).getFollows());
            // 地区名称
            if (StringUtil.isNotEmpty(user.getDistrict())) {
                District district = districtService.getByCode(user.getDistrict());
                if (district != null) {
                    vo.setDistrict(district.getDistrictName());
                }
            }
            // 城市名称
            if (StringUtil.isNotEmpty(user.getCity())) {
                District district = districtService.getByCode(user.getCity());
                if (district != null) {
                    vo.setCity(district.getDistrictName());
                }
            }
            // 省
            if (StringUtil.isNotEmpty(user.getProvince())) {
                District district = districtService.getByCode(user.getProvince());
                if (district != null) {
                    vo.setProvince(district.getDistrictName());
                }
            }

            vo.setStatus(user.getStatus());
            vo.setSex(user.getSex());

            vo.setUserLevel(user.getUserLevel());
            vo.setTeamLevel(user.getTeamLevel());

            vo.setSign(user.getSign());
            vo.setAvatar(user.getAvatar());
            vo.setFyNo(user.getFyNo());
            vo.setFyNoNum(user.getFyNoNum());
            vo.setPendantUrl(user.getPendantUrl());
            vo.setVip(user.getVip());
            vo.setHrnName(getHrnName(user.getAuthPay(), user.getFace(), user.getFaceAuth()));
            vo.setAuthPay(user.getAuthPay());
            vo.setFace(user.getFace());

            return Response.success().put("data", vo);
        } catch (Exception e) {
            logger.error("", e);
            return Response.fail("用户信息获取失败");
        }
    }


    // 1支付页面 2人脸认证页面 3不进页面
    private String getHrnName(String authPay, String face, String faceAuth) {
        if (User.FACE_AUTH_YES.equals(faceAuth)){
            return "已实名";
        }
        authPay = authPay == null ? "0" : authPay;
        face = face == null ? "0" : face;
        //hrn==1   跳支付     2，跳实名认证  3， 跳展示实名认证信息
        switch (authPay + face) {
            case "00":
                return "未实名";
            case "01":
                return "已认证未支付";
            case "10":
                return "已支付未认证";
            case "11":
                return "已实名";
        }
        return "未实名";
    }
}